const express = require('express');
const { 
  registerUser, 
  loginUser, 
  getUserProfile, 
  searchUsers, 
  sendFriendRequest, 
  respondToFriendRequest, 
  getFriends, 
  getFriendRequests,
  updateUserProfile,
  getUserById,
  uploadAvatar
} = require('../controllers/userController');
const { protect } = require('../middlewares/auth');
const { upload } = require('../middlewares/upload');

const router = express.Router();

// 公开路由
router.post('/', registerUser);
router.post('/login', loginUser);

// 需要认证的路由 - 固定路径路由必须放在动态参数路由前面
router.get('/profile', protect, getUserProfile);
router.put('/profile', protect, updateUserProfile);
router.post('/avatar', protect, upload.single('avatar'), uploadAvatar);
router.get('/search', protect, searchUsers);
router.post('/friend-requests', protect, sendFriendRequest);
router.put('/friend-requests/:requestId', protect, respondToFriendRequest);
router.get('/friends', protect, getFriends);
router.get('/friend-requests', protect, getFriendRequests);

// 动态参数路由放在最后
router.get('/:userId', protect, getUserById);

module.exports = router; 